using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Jaws.Core.Web.Controls.HtmlEditor
{
    public class Editor : EditorPart
    {

        private TextBox textBox = new TextBox();

        public Editor()
        {
            this.ID = "HtmlEditor";
        }

        protected override void CreateChildControls()
        {
            textBox.TextMode = TextBoxMode.MultiLine;
            Controls.Add(textBox);
        }

        public override bool ApplyChanges()
        {
            EnsureChildControls();
            Display part = WebPartToEdit as Display;
            if (part != null)
            {
                part.DisplayText = textBox.Text;
            }
            else 
            {
                return false;
            }
            return true;
        }

        public override void SyncChanges()
        {
            EnsureChildControls();
            Display part = WebPartToEdit as Display;
            if (part != null)
            {
                textBox.Text = part.DisplayText;
            }
        }
    }
}